﻿using System;
using System.Net.Configuration;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
using Secured3d.Auto.Pages;
using Secured3d.Auto.Utils;

namespace Secured3d.Auto.Helpers
{
    public class UploadBlock : BasePage
    {
        //Locators
        [FindsBy(How = How.Id, Using = "printer_type_1")] 
        private IWebElement maketbot_replicator_2x = null;

        [FindsBy(How = How.CssSelector, Using = "input[type=\"file\"]")] 
        private IWebElement fileElement = null;

        [CacheLookup]
        [FindsBy(How = How.Id, Using = "progressPercent")] 
        private IWebElement progressPercentValue = null;

        public UploadBlock ForPrinterType(PrinterType type)
        {
            switch (type)
            {
                    case PrinterType.Makerbot_Replicator_2:
                    maketbot_replicator_2x.Click();
                    break;
            }

            return this;
        }

        public void File(string filePath)
        {
            IJavaScriptExecutor java = Driver as IJavaScriptExecutor;

            java.ExecuteScript("arguments[0].setAttribute('style', '')", fileElement);
            if(fileElement.Displayed)
                fileElement.SendKeys(filePath);

            while (progressPercentValue.Text != "100%")
            {
                Thread.Sleep(100);
            }



        }
    }

    public enum PrinterType
    {
        Makerbot_Replicator_2
    }
}
